昨天在介紹ReplicaSet時有提及,目前官方文檔中建議使用Deployment,來取代ReplicationController和ReplicaSet。
We recommend using Deployments instead of directly using ReplicaSets, unless you require custom update orchestration or don't require updates at all
實際上Depolyment是一種高階抽象(high-level abstraction),可以將其理解為: 當建立一個Deployment資源,K8s會自動建立好ReplicaSet和所對應的Pods。
Deployment is a higher-level concept that manages ReplicaSets and provides declarative updates to Pods along with a lot of other useful features.
透過設定期望狀態,Deployment Controller會不斷監控並使其狀態符合預期,而以下列出常見的應用情境:
以下為Deployment設定檔範例
# deployment-definition.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80